//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class ChartBarRecord : ChartBiffRecord
    {
        private bool f100;
        private bool fHasShadow;
        private bool fStacked;
        private bool fTranspose;
        private ushort pcGap;
        private short pcOverlap;

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.Bar; }
        }

        private ushort Num
        {
            get
            {
                ushort result = 0;
                if (fTranspose) result |= 1;
                if (fStacked) result |= 2;
                if (f100) result |= 4;
                if (fHasShadow) result |= 8;
                return result;
            }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.Write(pcOverlap);
            context.Write(pcGap);
            context.Write(Num);
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            pcOverlap = context.ReadInt16();
            pcGap = context.ReadUInt16();
            ushort num = context.ReadUInt16();
            fTranspose = (num & 1) == 1;
            fStacked = (num & 2) == 2;
            f100 = (num & 4) == 4;
            fHasShadow = (num & 8) == 8;
            Contract.Assert(Num == num);
        }
    }
}